//
//  HJRequest.swift
//  SwfitBase
//
//  Created by rubick on 2023/1/16.
//

import Foundation
import Moya

///  请求Targets为Class

/** 此类仅仅是示例代码，不建议使用此类 */

@available(*, deprecated, message: "Use `normalProvider` instead, This is just an example method")
class HJBaseRequest : TargetType {
    var baseURL: URL {
        return URL(string: "https://esign.com/")!
    }
    var path: String {
        return ""
    }
    var method: Moya.Method {
        return .get
    }
    var task: Moya.Task {
        return .requestParameters(parameters: ["xxx": "xxx"], encoding: URLEncoding.queryString)
    }
    var headers: [String : String]? {
        return ["xxx": "xxx"]
    }
    // 单元测试 模拟的数据
    var sampleData: Data {
        return "{}".data(using: .utf8)!
    }
}

// MARK: 使用示例
private class HomeInfoRequest: HJBaseRequest {
    var channelId: Int
    init(_ channel: Int) {
        channelId = channel
    }
    override var path: String {
        return "user/\(channelId)"
    }
    override var method: Moya.Method {
        return .get
    }
    override var task: Moya.Task {
        let params = ["gender":1,"generation":1,"limit":20,"offset":0]
        return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
    }
}
private func getHomeInfo() {
    let req = HomeInfoRequest(13)
    HJNetworkRequestOld(req) { result in
        print(result)
    } failed: { errorMsg, hjError in
        print(errorMsg)
    }
}
